package com.daqsoft.controller.system;

import com.daqsoft.data.PermissionConfig;
import com.daqsoft.dto.GeneralResultEnum;
import com.daqsoft.permission.Verify;
import com.daqsoft.permission.VerifyType;
import com.daqsoft.service.system.PermissionManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 周麟东 on 11:54
 */
@RestController
@RequestMapping("permissionConfig")
@Verify(desc = "权限配置")
public class PermissionConfigController {

    @Autowired
    private PermissionManageService permissionManageService;


    @Verify(value = VerifyType.HAVE_PERMISSION,desc = "获取模块的权限配置")
    @RequestMapping("getAllPaths")
    public GeneralResultEnum getAllPaths(int moduleId){
        return GeneralResultEnum.SUCCESS.setData(permissionManageService.getPathTreeByModuleId(moduleId));
    }
    @RequestMapping("saveConfig")
    @Verify(value = VerifyType.HAVE_PERMISSION,desc = "保存模块的权限配置")
    public GeneralResultEnum saveConfig(@RequestParam("paths[]") String [] paths , int moduleId){
        permissionManageService.save(moduleId,paths);
        return GeneralResultEnum.SUCCESS;
    }
    @RequestMapping("getAllConfig")
    @Verify(value = VerifyType.HAVE_PERMISSION,desc = "获取全部权限配置")
    public GeneralResultEnum getAllConfig(){
        return GeneralResultEnum.SUCCESS.setData(permissionManageService.getAll());
    }
    @RequestMapping("removeConfig")
    @Verify(value = VerifyType.HAVE_PERMISSION,desc = "删除权限配置")
    public GeneralResultEnum removeConfig(int id){
        permissionManageService.remove(id);
        return GeneralResultEnum.SUCCESS;
    }


}
